package com.action;

import java.util.List;
import com.dao.UserDao;
import com.entity.User;
import com.dao.impl.UserDaoImpl;
import com.opensymphony.xwork2.ActionSupport;


public class LoginAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1222222L;
	private String name;
	private String password;
	
	

	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public String getPassword() {
		return password;
	}



	public void setPassword(String password) {
		this.password = password;
	}
	public String login() {
		UserDao userDao=new UserDaoImpl();
		List<User> list=userDao.login(name, password);
		if(list.size()>0){
			System.out.println("登录成功");
			return "loginsuccess";
		}else{
			System.out.println("用户名或密码错误");
			return "loginfail";
		}
	}
	public String register() {
		UserDao userDao=new UserDaoImpl();
		List<User>list=userDao.findUserByName(name);
		if (list.size()>0) {
			System.out.println("用户名为空或已存在");
			return "registerfail";	
		}else {
			User user = new User();
			user.setName(name);
			user.setPassword(password);
			boolean flag=userDao.register(user);
			if(flag){
				System.out.println("注册成功");
				return "registersuccess";
				
			}else{
				System.out.println("注册失败");
				return "registerfail";
			}
			
			
		}
		
	}

}
